﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WorldOfMUDra
{
    public class Clock : Ticker
    {
        int minutes;

        int TimeOfSunset = 420;

        public delegate void ClockEvent();

        List<ClockEvent> SunSetEvents = new List<ClockEvent>();

        public bool AfterSunset
        {
            get { return (minutes >= TimeOfSunset); }
        }

        public Clock()
        {

        }

        public void AddSunSetEvent(ClockEvent EventToAdd)
        {
            SunSetEvents.Add(EventToAdd);
        }

        protected override void OnTick(object source, System.Timers.ElapsedEventArgs e)
        {
            this.minutes += 1;
            if (this.minutes > 1440) this.minutes = 0;
            if (this.minutes == TimeOfSunset)
            {
                foreach (ClockEvent cevent in this.SunSetEvents)
                {
                    cevent();
                }
            }
        }
    }
}
